#include "st_sock_holder.h"
#include "sys_socket.h"
#include <iostream>
using std::cout;
using std::endl;

STSockHolder::STSockHolder(int sock):
    m_sock(sock)
{
}

STSockHolder::~STSockHolder()
{
    closesocket(m_sock);
}

bool STSockHolder::pushByte(char byte)
{
    cout << "STSockHolder::pushByte: " << byte << endl;
    return true;
}

/**
 * Return true if this connection is still useful.
 */
bool STSockHolder::pushEnd()
{
    return false;
}

bool STSockHolder::pushBytes(const char* bytes, unsigned int size)
{
    for (unsigned int i = 0; i < size; i++)
    {
        if (pushByte(bytes[i]) == false)
            return false;
    }
    return true;
}

int STSockHolder::send(const string& str)
{
    return ::send(m_sock, str.c_str(), str.length(), 0);
}

int STSockHolder::send(void* buffer, unsigned int size)
{
    return ::send(m_sock, (const char*)buffer, size, 0);
}
